import asyncio
import random

from fastapi import FastAPI, HTTPException

app = FastAPI()

@app.post("/request")
async def get_fake_data(seed: dict):
    random.seed(seed.get('seed'))
    sleep_time = random.random()*3
    await asyncio.sleep(sleep_time)
    if random.random() < 0.05:
        raise HTTPException(status_code=500, detail="Random error occurred")
    fake_data = {
        "id": random.randint(1, 1000),
        "name": f"Fake Name {random.randint(1, 100)}",
        "sleep":sleep_time,
        "age": random.randint(18, 60),
        "email": f"fake{random.randint(1, 1000)}@example.com"
    }
    return fake_data

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, port=8081)